﻿using System;
using System.Collections;
using System.Collections.Generic;

namespace Visitor
{
    public class Directory : Entry, IEnumerable<Entry>
    {
        private string name;
        private List<Entry> dir;

        public Directory(string name)
        {
            this.name = name;
            this.dir = new List<Entry>();
        }

        public new Entry Add(Entry entry)
        {
            dir.Add(entry);
            return this;
        }


        public override string GetName()
        {
            return name;
        }

        public override int GetSize()
        {
            int size = 0;

            foreach (Entry entry in dir)
            {
                size += entry.GetSize();
            }

            return size;
        }

        public override void Accept(Visitor v)
        {
            v.Visit(this);
        }

        #region IEnumerable<Directory> メンバ

        public IEnumerator<Entry> GetEnumerator()
        {
            foreach (Entry d in dir)
            {
                yield return d;
            }
        }

        #endregion

        #region IEnumerable メンバ

        IEnumerator IEnumerable.GetEnumerator()
        {
            throw new NotImplementedException();
        }

        #endregion
    }
}
